import requests,pytest
from conftest import *

# 第1条测试用例
def test_01(login):
    j_id=login
    urls='http://47.113.229.131:9080/jeewms/baPlatformController.do?doAdd'
    headers1={
        'content-type':'application/x-www-form-urlencoded',
        'Cookie':f'JSESSIONID={j_id}'
    }
    datas={
        'platformCode':'114514112',
        'platformName':'闪贷旋风劈'
    }
    add=requests.post(url=urls,headers=headers1,data=datas)
    add_json=add.json()
    print(add_json)
    try:
        # 断言success是否为True
        assert add_json['success'] == True
        # 断言响应时间是否小于2秒
        assert add.elapsed.total_seconds() <= 2
        # 断言状态码是否为200
        assert add.status_code == 200
    except Exception as e:
        print(e)
# 第2条测试用例
def test_02(login):
    j_id=login
    urls='http://47.113.229.131:9080/jeewms/baPlatformController.do?doUpdate'
    headers1={
        'content-type':'application/x-www-form-urlencoded',
        'Cookie':f'JSESSIONID={j_id}'
    }
    datas={
        'id':'2c9efaca98b281540199175349b60997',
        'zhongWenQch':'114534112',
        'zhuJiMa':'血色月风暴'
    }
    up=requests.post(url=urls,headers=headers1,data=datas)
    up_json=up.json()
    print(up_json)
    try:
        # 断言msg是否为月台主数据更新成功
        assert up_json['msg'] == '月台主数据更新成功'
        # 断言响应时间是否小于2秒
        assert up_json.elapsed.total_seconds() <= 2
        # 断言状态码是否为200
        assert up_json.status_code == 200
    except Exception as e:
        print(e)

# 第3条测试用例
def test_03(login):
    j_id=login
    urls='http://47.113.229.131:9080/jeewms/baPlatformController.do?doDel'
    headers1={
        'content-type':'application/x-www-form-urlencoded',
        'Cookie':f'JSESSIONID={j_id}'
    }
    datas={
        'id':'2c9efaca98b2815401992bed5a470b39'
    }
    up=requests.post(url=urls,headers=headers1,data=datas)
    up_json=up.json()
    print(up_json)
    try:
        # 断言msg是否为月台主数据更新成功
        assert up_json['msg'] == '月台主数据删除成功'
        # 断言响应时间是否小于2秒
        assert up_json.elapsed.total_seconds() <= 2
        # 断言状态码是否为200
        assert up_json.status_code == 200
    except Exception as e:
        print(e)

# 第4条测试用例
def test_04(login):
    j_id=login
    urls='http://47.113.229.131:9080/jeewms/baPlatformController.do?doDel'
    headers1={
        'content-type':'application/x-www-form-urlencoded',
        'Cookie':f'JSESSIONID={j_id}'
    }
    # 测试id为空
    datas={
        'id':''
    }
    up=requests.post(url=urls,headers=headers1,data=datas)
    up_json=up.json()
    print(up_json)
    try:
        # 断言响应时间是否小于2秒
        assert up_json.elapsed.total_seconds() <= 2
        # 断言状态码是否为200
        assert up_json.status_code == 200
    except Exception as e:
        print(e)
# 第5条测试用例
def test_05(login):
    j_id=login
    urls='http://47.113.229.131:9080/jeewms/baPlatformController.do?doDel'
    headers1={
        'content-type':'application/x-www-form-urlencoded',
        'Cookie':f'JSESSIONID={j_id}'
    }
    # 测试id为字母
    datas={
        'id':'case'
    }
    up=requests.post(url=urls,headers=headers1,data=datas)
    up_json=up.json()
    print(up_json)
    try:
        # 断言响应时间是否小于2秒
        assert up_json.elapsed.total_seconds() <= 2
        # 断言状态码是否为200
        assert up_json.status_code == 200
    except Exception as e:
        print(e)
# 第6条测试用例
def test_06(login):
    j_id=login
    urls='http://47.113.229.131:9080/jeewms/baPlatformController.do'
    headers1={
        'content-type':'application/x-www-form-urlencoded',
        'Cookie':f'JSESSIONID={j_id}'
    }
    par={
        'datagrid':'',
        'field':'id,createName,createBy,createDate,updateName,updateBy,updateDate,sysOrgCode,sysCompanyCode,platformCode,platformName,platformDel,'
    }
    # 测试 platformCode值为数字
    datas={
        'platformCode': '01',
        'platformName':'',
        'page':'1',
        'rows': '10'
    }
    up=requests.post(url=urls,params=par,headers=headers1,data=datas)
    up_json=up.json()
    print(up_json)
    try:
        # 断言响应时间是否小于2秒
        assert up_json.elapsed.total_seconds() <= 2
        # 断言状态码是否为200
        assert up_json.status_code == 200
    except Exception as e:
        print(e)

# 第7条测试用例
def test_07(login):
    j_id=login
    urls='http://47.113.229.131:9080/jeewms/baPlatformController.do'
    headers1={
        'content-type':'application/x-www-form-urlencoded',
        'Cookie':f'JSESSIONID={j_id}'
    }
    par={
        'datagrid':'',
        'field':'id,createName,createBy,createDate,updateName,updateBy,updateDate,sysOrgCode,sysCompanyCode,platformCode,platformName,platformDel,'
    }
    # 测试 platformCode值为英文
    datas={
        'platformCode': 'a',
        'platformName':'',
        'page':'1',
        'rows': '10'
    }
    up=requests.post(url=urls,params=par,headers=headers1,data=datas)
    up_json=up.json()
    print(up_json)
    try:
        # 断言响应时间是否小于2秒
        assert up_json.elapsed.total_seconds() <= 2
        # 断言状态码是否为200
        assert up_json.status_code == 200
    except Exception as e:
        print(e)

# 第8条测试用例
def test_08(login):
    j_id=login
    urls='http://47.113.229.131:9080/jeewms/baPlatformController.do'
    headers1={
        'content-type':'application/x-www-form-urlencoded',
        'Cookie':f'JSESSIONID={j_id}'
    }
    par={
        'datagrid':'',
        'field':'id,createName,createBy,createDate,updateName,updateBy,updateDate,sysOrgCode,sysCompanyCode,platformCode,platformName,platformDel,'
    }
    # 测试 platformCode值为空
    datas={
        'platformCode': '',
        'platformName':'',
        'page':'1',
        'rows': '10'
    }
    up=requests.post(url=urls,params=par,headers=headers1,data=datas)
    up_json=up.json()
    print(up_json)
    try:
        # 断言响应时间是否小于2秒
        assert up_json.elapsed.total_seconds() <= 2
        # 断言状态码是否为200
        assert up_json.status_code == 200
    except Exception as e:
        print(e)
# 第9条测试用例
def test_09(login):
    j_id=login
    urls='http://47.113.229.131:9080/jeewms/baPlatformController.do'
    headers1={
        'content-type':'application/x-www-form-urlencoded',
        'Cookie':f'JSESSIONID={j_id}'
    }
    par={
        'datagrid':'',
        'field':'id,createName,createBy,createDate,updateName,updateBy,updateDate,sysOrgCode,sysCompanyCode,platformCode,platformName,platformDel,'
    }
    # 测试 rows 为 最小
    datas={
        'platformCode': '',
        'platformName':'',
        'page':'1',
        'rows': '1'
    }
    up=requests.post(url=urls,params=par,headers=headers1,data=datas)
    up_json=up.json()
    print(up_json)
    try:
        # 断言响应时间是否小于2秒
        assert up_json.elapsed.total_seconds() <= 2
        # 断言状态码是否为200
        assert up_json.status_code == 200
    except Exception as e:
        print(e)

# 第10条测试用例
def test_10(login):
    j_id=login
    urls='http://47.113.229.131:9080/jeewms/baPlatformController.do'
    headers1={
        'content-type':'application/x-www-form-urlencoded',
        'Cookie':f'JSESSIONID={j_id}'
    }
    par={
        'datagrid':'',
        'field':'id,createName,createBy,createDate,updateName,updateBy,updateDate,sysOrgCode,sysCompanyCode,platformCode,platformName,platformDel,'
    }
    # 测试 platformName 为 中文
    datas={
        'platformCode': '',
        'platformName':'闪电',
        'page':'1',
        'rows': '10'
    }
    up=requests.post(url=urls,params=par,headers=headers1,data=datas)
    up_json=up.json()
    print(up_json)
    try:
        # 断言响应时间是否小于2秒
        assert up_json.elapsed.total_seconds() <= 2
        # 断言状态码是否为200
        assert up_json.status_code == 200
    except Exception as e:
        print(e)

